import { Message, MessageBox } from "element-ui";
import { getSession } from "@/utils/support";
import { getToken } from '@/utils/auth'
export default ({ app }) => {
  app.router.beforeEach((to, from, next) => {
    if (process.client) {
      const token = getToken("token");
      // 用户名
      const name = getSession("username") || localStorage.getItem("username");
      console.log(token);
      console.log(name);
      if (
        token === null &&
        name === null &&
        to.path !== "/" &&
        to.path !== "/login" &&
        to.path !== "/index" &&
        to.path !== "/register" &&
        to.path !== "/changeCity" &&
        to.path !== "/404" &&
        to.path !== "/detail:id" &&
        to.path !== "/products"
      ) {
        Message({
          type: "error",
          message: "很抱歉，尚未登录，无法访问！0001"
        });
        next("/login");
      } else {
        next();
      }
    }
  });
};
